package com.dts.servlet;

import jakarta.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

public class InitParameterServlet implements Servlet {

    private ServletConfig servletConfig;
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        this.servletConfig = servletConfig;
        System.out.println("初始化语句1");
    }

    @Override
    public ServletConfig getServletConfig() {
        return servletConfig;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("service方法执行了");
        servletResponse.setContentType("text/html;charset=UTF-8");
        PrintWriter out = servletResponse.getWriter();
        out.write("<table>");
        out.write("<tr>");
        out.write("<td>用户名：</td>");
        out.write("<td>" + this.servletConfig.getInitParameter("username") + "</td>");
        out.write("</tr>");
        out.write("<tr>");
        out.write("<td>密码：</td>");
        out.write("<td>" + this.servletConfig.getInitParameter("password") + "</td>");
        out.write("</tr>");
        out.write("</table>");
        out.close();
    }

    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {
        System.out.println("销毁语句");
    }
}
